<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>JavaScript Benchmark: array filling</title>
    <script type="text/javascript" src="benchmarker.js"></script>
    <script type="text/javascript">
      new Benchmarker({}, // no methods, we'll define them at setup stage
        {
          description: 'array populating speed ("push" vs "pre-initialization")',
          atInit: function() {
            // prepare core test methods...
            this.pushing = function(n) { // enlarge an initially empty array
              var rv = [];
              for (var i = n; --i >= 0;) rv.push(1);
              return rv;
            };
            this.preinit = function(n) { // set values to a preinitialized array
              var rv = new Array(n);
              for (var i = n; --i >= 0;) rv[i] = (1);
              return rv;
            };
          },
          setup: function() {
            // building benchmark sets...
            $w('1 5 10 100 200').each(function(len) {
              var set = {};
              $w('pushing preinit').each(function(func) {
                eval('set["' + func + '"] = function(){ this.' + func + '(' + len + ')}');
              });
              methodSets.push( { name: 'array.length = ' + len, methods: set });
            });
          }
        }
      );
    </script>
  </head>
  <body>
  </body>
</html>
